class Solution {
    public int[] searchRange(int[] nums, int target) {
        int[] re = new int[2];
        re[0] = -1;
        re[1] = -1;
        int len = nums.length;
        int left = 0;
        int right = len-1;
        int mid;
        //二分查找，如果找到目标值
        while ( left <= right ){
            mid = (left+right)/2;
            if(nums[mid] == target){
                right = mid ;
                left = mid ;
                while(right < len-1 && nums[right+1] == target) right++;
                while(left >= 1 && nums[left-1] == target) left--;
                re[0] = left;
                re[1] = right;
                return re;
            }else if(nums[mid] > target){
                right = mid - 1;
            }else{
                left = mid + 1;
            }
        } 
        return re;
    } 
}